<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style></style>
    </head>
    <body>
        <button>快速点击</button>
        <script src="../jquery.min.js"></script>
        <script>
            //防抖函数
            let timer = null
            function throttle() {
                timer = setTimeout(function () {
                    console.log(11)
                }, 500)
                $('button').on('click', function () {
                    if (timer) {
                        clearTimeout(timer)
                        throttle()
                    }
                })
            }
            throttle()

            // let timer = 111
            // function throttle() {
            //     $('button').on('click', function () {
            //         if (timer) {
            //             clearTimeout(timer)
            //             timer = setTimeout(function () {
            //                 console.log(11)
            //             }, 500)
            //         }
            //     })
            // }
            // throttle()
        </script>
    </body>
</html>
